package com.hyperboost.handler;

import com.hyperboost.exception.BaseException;
import com.hyperboost.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理自定义业务异常
     * @param e
     * @return
     */
    @ExceptionHandler(BaseException.class)
    public Result BaseExceptionHandler(BaseException e) {

        log.error("业务异常：{}",e.getMessage());

        // 业务异常，返回错误信息
        return Result.error(e.getMessage());
    }
}
